﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Awaken.Utils.WidgetCode;
using System.Runtime.Caching;

namespace Awaken.MessageProvider
{
    public class MessageContext
    {
        public MessageModel _msgModel = null;

        public IMessage _message = null;

        public bool IsSuccess { get; set; }

        public string Msg { get; set; }

        public MessageContext(MessageModel message)
        {
            _msgModel = message;

            MessageMethod method = EnumHelper.GetValue<MessageMethod>(message.MessageMethod);

            switch (method)
            {
                case MessageMethod.MLINK:
                    _message = new MLinkMessage();
                    break;
                default:

                    _message = new MLinkMessage();
                    break;
            }
        }

        public bool SendMsg()
        {
            if (string.IsNullOrWhiteSpace(_msgModel.Phone)) return false;

            bool result = false;

            try
            {
                result = _message.Send(_msgModel);
            }
            catch (Exception ex)
            {
                Msg = ex.ToString();
            }

            return result;
        }
    }
}
